package com.Tadama.Forms;

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Ticker;
import com.Tadama.MIDlet.TadamaMIDlet;

public class SplashScreen extends Canvas implements Runnable{

    private Image mImage;
    private TadamaMIDlet mainMIDlet;
    private Ticker ticker;
    
    public SplashScreen(TadamaMIDlet projectMIDlet){
        this.setTitle(" ");
        this.mainMIDlet = projectMIDlet;
        ticker = new Ticker ("Toma de Pedidos, Devoluciones");
        this.setTicker(ticker);
        try{
            mImage = Image.createImage("/com/Tadama/img/Logo.png");
            Thread t = new Thread(this);
            t.start();
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }
    public void paint(Graphics g) {
        int width = getWidth(),height = getHeight();
        g.setColor(255, 255, 255); //setiamos el color de fondo
        g.fillRect(0,0, width, height);
        g.drawImage(mImage, width / 2, height / 2,Graphics.HCENTER | Graphics.VCENTER);
    }
    
    public void dismiss() throws IOException {
        if (isShown())
            Display.getDisplay(mainMIDlet).setCurrent(new frmLogin(mainMIDlet));
    }    

    public void run() {
        try {
            Thread.sleep(6000);//se muestra por 3 segundos
        }
        catch (InterruptedException e) {
            System.out.println("InterruptedException");
        }
        try {
            dismiss();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void keyReleased(int keyCode) {
        try {
            dismiss();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void pointerReleased(int x, int y) {
        try {
            dismiss();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }   
}